<template>
  <div id="home">
    <el-container>
      <el-header>
        <div class="logo">
          <img src="../assets/logo (2).png" alt="">
          <div class="title">电商后台管理系统</div>
        </div>
        <el-button type="info" @click="quit">退出</el-button>
      </el-header>
      <el-container>
      <el-aside :width="collapse ?'64px':'200px'" style="transition:width 1s">
         <div class="btn" @click="btn">|||</div>
    <el-menu
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eff"
      :collapse="collapse"
      :collapse-transition="false"
      :router='true'
      >
      <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
        <template slot="title">
          <i :class="objectIcon[item.id]"></i>
          <span style="padding-left:10px">{{item.authName}}</span>
        </template>
       

          <el-menu-item :index="'/'+childItem.path+''" v-for="childItem in item.children" :key="childItem.id">
            <i class="el-icon-menu"></i>
          <span>{{childItem.authName}}</span>
          </el-menu-item>


      </el-submenu>
    </el-menu>
 
        </el-aside>
        <el-main>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>


export default {
  name: 'Home',
  data(){
    return{
      menuList:[],
      objectIcon:{
        '125':'iconfont el-icon-user-solid',
        '103':'iconfont el-icon-question',
        '101':'iconfont el-icon-s-home',
        '102':'iconfont el-icon-s-unfold',
        '145':'iconfont el-icon-s-comment',
      },
      collapse:false
    }
  },
  created(){
    this.getMenuList()
  },
  methods:{
    //退出功能
    quit(){
      localStorage.removeItem('token')
      this.$router.push('/login')
    },
    //获取首页左侧导航栏菜单接口
    async getMenuList(){
      const {data: res}=await this.$http.get('menus')
      console.log(res);
      this.menuList=res.data
    },
    // 侧边栏展开与缩放
    btn(){
      this.collapse=!this.collapse
    }
  }
}
</script>
<style lang="less" scoped>
 #home{
  height: 100%;
  .el-container{
    height:100%;
    .el-header{
      background-color: #373d41;
      display: flex;
      justify-content: space-between;
      .logo{
        display: flex;
        // justify-content: center;
        align-items: center;
        img{
          width: 50px;
        }
        .title{
          color: #fff;
          padding-left: 10px;
        }
      }
      .el-button{
       margin: 10px 0;
      }
    }
    .el-aside{
      background-color: #333744;
      .btn{
        background-color: #909399;
        font-size: 16px;
        color: #fff;
        text-align: center;
        line-height: 30px;
      }
      .el-menu{
        border-right: 0;
      }
    }
    .el-main{
      background-color: #eaedf1;
    }
  }
 }
</style>